<!DOCTYPE html>
<html lang="zh-CN">
<head>
  <meta charset="UTF-8">
<meta name="viewport" content="width=device-width">
<meta name="theme-color" content="#222">
<meta name="generator" content="Hexo 5.4.0">


  <link rel="apple-touch-icon" sizes="180x180" href="/images/apple-touch-icon-next.png">
  <link rel="icon" type="image/png" sizes="32x32" href="/images/favicon-32x32-next.png">
  <link rel="icon" type="image/png" sizes="16x16" href="/images/favicon-16x16-next.png">
  <link rel="mask-icon" href="/images/logo.svg" color="#222">

<link rel="stylesheet" href="/css/main.css">



<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/@fortawesome/fontawesome-free@5.15.3/css/all.min.css" integrity="sha256-2H3fkXt6FEmrReK448mDVGKb3WW2ZZw35gI7vqHOE4Y=" crossorigin="anonymous">
  <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/animate.css@3.1.1/animate.min.css" integrity="sha256-PR7ttpcvz8qrF57fur/yAx1qXMFJeJFiA6pSzWi0OIE=" crossorigin="anonymous">

<script class="next-config" data-name="main" type="application/json">{"hostname":"example.com","root":"/","images":"/images","scheme":"Gemini","version":"8.7.0","exturl":false,"sidebar":{"position":"right","display":"post","padding":18,"offset":15},"copycode":false,"bookmark":{"enable":false,"color":"#222","save":"auto"},"fancybox":false,"mediumzoom":false,"lazyload":false,"pangu":false,"comments":{"style":"tabs","active":null,"storage":true,"lazyload":false,"nav":null},"motion":{"enable":true,"async":false,"transition":{"post_block":"fadeIn","post_header":"fadeInDown","post_body":"fadeInDown","coll_header":"fadeInLeft","sidebar":"fadeInUp"}},"prism":false,"i18n":{"placeholder":"搜索...","empty":"没有找到任何搜索结果：${query}","hits_time":"找到 ${hits} 个搜索结果（用时 ${time} 毫秒）","hits":"找到 ${hits} 个搜索结果"},"path":"/search.xml","localsearch":{"enable":true,"trigger":"auto","top_n_per_article":1,"unescape":false,"preload":false}}</script><script src="/js/config.js"></script>
<meta name="description" content="本文通过CSS绘制各种图形的方法大概有以下四种​    使用相对的宽高单位，例如宽高相等的 正方形 ​    使用 border配合透明颜色来实现的 等腰三角、等腰梯形 ​    使用 boder-radius:50%实现的 圆和椭圆 ​    使用 transform: skew(); transform: rotate(); 配合锚点 transform-origin 实现的 平行四边形和任意">
<meta property="og:type" content="article">
<meta property="og:title" content="通过CSS绘制各种图形">
<meta property="og:url" content="http://example.com/%E9%80%9A%E8%BF%87CSS%E7%BB%98%E5%88%B6%E5%90%84%E7%A7%8D%E5%9B%BE%E5%BD%A2/index.html">
<meta property="og:site_name" content="受靈夢的博客">
<meta property="og:description" content="本文通过CSS绘制各种图形的方法大概有以下四种​    使用相对的宽高单位，例如宽高相等的 正方形 ​    使用 border配合透明颜色来实现的 等腰三角、等腰梯形 ​    使用 boder-radius:50%实现的 圆和椭圆 ​    使用 transform: skew(); transform: rotate(); 配合锚点 transform-origin 实现的 平行四边形和任意">
<meta property="og:locale" content="zh_CN">
<meta property="og:image" content="https://typora555.oss-cn-shanghai.aliyuncs.com/typora555/image-20210908221011696.png">
<meta property="og:image" content="https://typora555.oss-cn-shanghai.aliyuncs.com/typora555/image-20210908223602264.png">
<meta property="og:image" content="https://typora555.oss-cn-shanghai.aliyuncs.com/typora555/image-20210908225950082.png">
<meta property="og:image" content="https://typora555.oss-cn-shanghai.aliyuncs.com/typora555/image-20210908225045436.png">
<meta property="og:image" content="https://typora555.oss-cn-shanghai.aliyuncs.com/typora555/image-20210908225131527.png">
<meta property="og:image" content="https://typora555.oss-cn-shanghai.aliyuncs.com/typora555/image-20210908225204180.png">
<meta property="og:image" content="https://typora555.oss-cn-shanghai.aliyuncs.com/typora555/image-20210908230844656.png">
<meta property="og:image" content="https://typora555.oss-cn-shanghai.aliyuncs.com/typora555/image-20210908231307441.png">
<meta property="og:image" content="https://typora555.oss-cn-shanghai.aliyuncs.com/typora555/image-20210908232415598.png">
<meta property="og:image" content="https://typora555.oss-cn-shanghai.aliyuncs.com/typora555/image-20210909002520040.png">
<meta property="og:image" content="https://typora555.oss-cn-shanghai.aliyuncs.com/typora555/image-20210908233102189.png">
<meta property="og:image" content="https://typora555.oss-cn-shanghai.aliyuncs.com/typora555/image-20210908233929505.png">
<meta property="article:published_time" content="2021-09-08T13:38:14.000Z">
<meta property="article:modified_time" content="2021-09-08T16:30:57.553Z">
<meta property="article:author" content="受靈夢">
<meta property="article:tag" content="HTML">
<meta property="article:tag" content="CSS">
<meta name="twitter:card" content="summary">
<meta name="twitter:image" content="https://typora555.oss-cn-shanghai.aliyuncs.com/typora555/image-20210908221011696.png">


<link rel="canonical" href="http://example.com/%E9%80%9A%E8%BF%87CSS%E7%BB%98%E5%88%B6%E5%90%84%E7%A7%8D%E5%9B%BE%E5%BD%A2/">



<script class="next-config" data-name="page" type="application/json">{"sidebar":"","isHome":false,"isPost":true,"lang":"zh-CN","comments":true,"permalink":"http://example.com/%E9%80%9A%E8%BF%87CSS%E7%BB%98%E5%88%B6%E5%90%84%E7%A7%8D%E5%9B%BE%E5%BD%A2/","path":"通过CSS绘制各种图形/","title":"通过CSS绘制各种图形"}</script>

<script class="next-config" data-name="calendar" type="application/json">""</script>
<title>通过CSS绘制各种图形 | 受靈夢的博客</title>
  




  <noscript>
    <link rel="stylesheet" href="/css/noscript.css">
  </noscript>
</head>

<body itemscope itemtype="http://schema.org/WebPage" class="use-motion">
  <div class="headband"></div>

  <main class="main">
    <header class="header" itemscope itemtype="http://schema.org/WPHeader">
      <div class="header-inner"><div class="site-brand-container">
  <div class="site-nav-toggle">
    <div class="toggle" aria-label="切换导航栏" role="button">
        <span class="toggle-line"></span>
        <span class="toggle-line"></span>
        <span class="toggle-line"></span>
    </div>
  </div>

  <div class="site-meta">

    <a href="/" class="brand" rel="start">
      <i class="logo-line"></i>
      <h1 class="site-title">受靈夢的博客</h1>
      <i class="logo-line"></i>
    </a>
      <p class="site-subtitle" itemprop="description">悟道之旅</p>
  </div>

  <div class="site-nav-right">
    <div class="toggle popup-trigger">
        <i class="fa fa-search fa-fw fa-lg"></i>
    </div>
  </div>
</div>



<nav class="site-nav">
  <ul class="main-menu menu">
        <li class="menu-item menu-item-home"><a href="/" rel="section"><i class="fa fa-home fa-fw"></i>首页</a></li>
        <li class="menu-item menu-item-tags"><a href="/tags/" rel="section"><i class="fa fa-tags fa-fw"></i>标签<span class="badge">5</span></a></li>
        <li class="menu-item menu-item-categories"><a href="/categories/" rel="section"><i class="fa fa-th fa-fw"></i>分类<span class="badge">0</span></a></li>
        <li class="menu-item menu-item-archives"><a href="/archives/" rel="section"><i class="fa fa-archive fa-fw"></i>归档<span class="badge">4</span></a></li>
      <li class="menu-item menu-item-search">
        <a role="button" class="popup-trigger"><i class="fa fa-search fa-fw"></i>搜索
        </a>
      </li>
  </ul>
</nav>



  <div class="search-pop-overlay">
    <div class="popup search-popup"><div class="search-header">
  <span class="search-icon">
    <i class="fa fa-search"></i>
  </span>
  <div class="search-input-container">
    <input autocomplete="off" autocapitalize="off" maxlength="80"
           placeholder="搜索..." spellcheck="false"
           type="search" class="search-input">
  </div>
  <span class="popup-btn-close" role="button">
    <i class="fa fa-times-circle"></i>
  </span>
</div>
<div class="search-result-container no-result">
  <div class="search-result-icon">
    <i class="fa fa-spinner fa-pulse fa-5x"></i>
  </div>
</div>

    </div>
  </div>

</div>
        
  
  <div class="toggle sidebar-toggle" role="button">
    <span class="toggle-line"></span>
    <span class="toggle-line"></span>
    <span class="toggle-line"></span>
  </div>

  <aside class="sidebar">

    <div class="sidebar-inner sidebar-nav-active sidebar-toc-active">
      <ul class="sidebar-nav">
        <li class="sidebar-nav-toc">
          文章目录
        </li>
        <li class="sidebar-nav-overview">
          站点概览
        </li>
      </ul>

      <div class="sidebar-panel-container">
        <!--noindex-->
        <div class="post-toc-wrap sidebar-panel">
            <div class="post-toc animated"><ol class="nav"><li class="nav-item nav-level-4"><a class="nav-link" href="#%E6%9C%AC%E6%96%87%E9%80%9A%E8%BF%87CSS%E7%BB%98%E5%88%B6%E5%90%84%E7%A7%8D%E5%9B%BE%E5%BD%A2%E7%9A%84%E6%96%B9%E6%B3%95%E5%A4%A7%E6%A6%82%E6%9C%89%E4%BB%A5%E4%B8%8B%E5%9B%9B%E7%A7%8D"><span class="nav-number">1.</span> <span class="nav-text">本文通过CSS绘制各种图形的方法大概有以下四种</span></a></li><li class="nav-item nav-level-4"><a class="nav-link" href="#%E5%AE%BD%E9%AB%98%E7%9B%B8%E7%AD%89%E7%9A%84%E6%AD%A3%E6%96%B9%E5%BD%A2"><span class="nav-number">2.</span> <span class="nav-text">宽高相等的正方形</span></a></li><li class="nav-item nav-level-4"><a class="nav-link" href="#%E7%AD%89%E8%85%B0%E4%B8%89%E8%A7%92%E5%BD%A2"><span class="nav-number">3.</span> <span class="nav-text">等腰三角形</span></a></li><li class="nav-item nav-level-4"><a class="nav-link" href="#%E7%9B%B4%E8%A7%92%E6%A2%AF%E5%BD%A2"><span class="nav-number">4.</span> <span class="nav-text">直角梯形</span></a></li><li class="nav-item nav-level-4"><a class="nav-link" href="#%E7%AD%89%E8%85%B0%E6%A2%AF%E5%BD%A2"><span class="nav-number">5.</span> <span class="nav-text">等腰梯形</span></a></li><li class="nav-item nav-level-4"><a class="nav-link" href="#%E5%9C%86%E4%B8%8E%E6%A4%AD%E5%9C%86"><span class="nav-number">6.</span> <span class="nav-text">圆与椭圆</span></a></li><li class="nav-item nav-level-4"><a class="nav-link" href="#%E5%B9%B3%E8%A1%8C%E5%9B%9B%E8%BE%B9%E5%BD%A2"><span class="nav-number">7.</span> <span class="nav-text">平行四边形</span></a></li><li class="nav-item nav-level-4"><a class="nav-link" href="#%E4%BB%BB%E6%84%8F%E8%A7%92%E5%BA%A6%E6%89%87%E5%BD%A2"><span class="nav-number">8.</span> <span class="nav-text">任意角度扇形</span></a></li></ol></div>
        </div>
        <!--/noindex-->

        <div class="site-overview-wrap sidebar-panel">
          <div class="site-overview">
            <div class="site-author site-overview-item animated" itemprop="author" itemscope itemtype="http://schema.org/Person">
    <img class="site-author-image" itemprop="image" alt="受靈夢"
      src="/images/youkuli.png">
  <p class="site-author-name" itemprop="name">受靈夢</p>
  <div class="site-description" itemprop="description">本博客用于记录前端学习者的学习路程，悟道不可避免！！！</div>
</div>
<div class="site-state-wrap site-overview-item animated">
  <nav class="site-state">
      <div class="site-state-item site-state-posts">
        <a href="/archives/">
          <span class="site-state-item-count">4</span>
          <span class="site-state-item-name">日志</span>
        </a>
      </div>
      <div class="site-state-item site-state-tags">
          <a href="/tags/">
        <span class="site-state-item-count">5</span>
        <span class="site-state-item-name">标签</span></a>
      </div>
  </nav>
</div>



          </div>
        </div>
      </div>
    </div>
  </aside>
  <div class="sidebar-dimmer"></div>


    </header>

    
  <div class="back-to-top" role="button" aria-label="返回顶部">
    <i class="fa fa-arrow-up"></i>
    <span>0%</span>
  </div>

<noscript>
  <div class="noscript-warning">Theme NexT works best with JavaScript enabled</div>
</noscript>


    <div class="main-inner post posts-expand">


  


<div class="post-block">
  
  

  <article itemscope itemtype="http://schema.org/Article" class="post-content" lang="zh-CN">
    <link itemprop="mainEntityOfPage" href="http://example.com/%E9%80%9A%E8%BF%87CSS%E7%BB%98%E5%88%B6%E5%90%84%E7%A7%8D%E5%9B%BE%E5%BD%A2/">

    <span hidden itemprop="author" itemscope itemtype="http://schema.org/Person">
      <meta itemprop="image" content="/images/youkuli.png">
      <meta itemprop="name" content="受靈夢">
      <meta itemprop="description" content="本博客用于记录前端学习者的学习路程，悟道不可避免！！！">
    </span>

    <span hidden itemprop="publisher" itemscope itemtype="http://schema.org/Organization">
      <meta itemprop="name" content="受靈夢的博客">
    </span>
      <header class="post-header">
        <h1 class="post-title" itemprop="name headline">
          通过CSS绘制各种图形
        </h1>

        <div class="post-meta-container">
          <div class="post-meta">
    <span class="post-meta-item">
      <span class="post-meta-item-icon">
        <i class="far fa-calendar"></i>
      </span>
      <span class="post-meta-item-text">发表于</span>

      <time title="创建时间：2021-09-08 21:38:14" itemprop="dateCreated datePublished" datetime="2021-09-08T21:38:14+08:00">2021-09-08</time>
    </span>
      <span class="post-meta-item">
        <span class="post-meta-item-icon">
          <i class="far fa-calendar-check"></i>
        </span>
        <span class="post-meta-item-text">更新于</span>
        <time title="修改时间：2021-09-09 00:30:57" itemprop="dateModified" datetime="2021-09-09T00:30:57+08:00">2021-09-09</time>
      </span>

  
</div>

        </div>
      </header>

    
    
    
    <div class="post-body" itemprop="articleBody">
        <h4 id="本文通过CSS绘制各种图形的方法大概有以下四种"><a href="#本文通过CSS绘制各种图形的方法大概有以下四种" class="headerlink" title="本文通过CSS绘制各种图形的方法大概有以下四种"></a>本文通过CSS绘制各种图形的方法大概有以下四种</h4><p>​    使用相对的宽高单位，例如宽高相等的 <strong>正方形</strong></p>
<p>​    使用 border配合透明颜色来实现的 <strong>等腰三角</strong>、<strong>等腰梯形</strong></p>
<p>​    使用 boder-radius:50%实现的 <strong>圆</strong>和<strong>椭圆</strong></p>
<p>​    使用 transform: skew(); transform: rotate(); 配合锚点 transform-origin 实现的 <strong>平行四边形</strong>和<strong>任意角度扇形</strong></p>
<span id="more"></span>

<br>

<h4 id="宽高相等的正方形"><a href="#宽高相等的正方形" class="headerlink" title="宽高相等的正方形"></a>宽高相等的正方形</h4><img src="https://typora555.oss-cn-shanghai.aliyuncs.com/typora555/image-20210908221011696.png" alt="image-20210908221011696" style='width:100px;'/>

<p>​    通过 vw单位实现</p>
<figure class="highlight css"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br></pre></td><td class="code"><pre><span class="line"><span class="selector-class">.square</span> &#123;</span><br><span class="line">    <span class="attribute">width</span>: <span class="number">10vw</span>;</span><br><span class="line">    <span class="attribute">height</span>: <span class="number">10vw</span>;</span><br><span class="line">    <span class="attribute">background-color</span>: <span class="built_in">rgb</span>(<span class="number">0</span>, <span class="number">0</span>, <span class="number">0</span>);</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>



<p>​    通过子元素margin/padding实现</p>
<figure class="highlight css"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br></pre></td><td class="code"><pre><span class="line"><span class="selector-class">.square</span> &#123;</span><br><span class="line">    <span class="attribute">width</span>: <span class="number">20%</span>;</span><br><span class="line">    <span class="attribute">background-color</span>: black;</span><br><span class="line"></span><br><span class="line">    <span class="comment">/* 触发 BFC避免高度塌陷 */</span></span><br><span class="line">    <span class="attribute">overflow</span>: hidden;</span><br><span class="line">&#125;</span><br><span class="line"></span><br><span class="line"><span class="comment">/* 通过伪元素撑开父元素的高 */</span></span><br><span class="line"><span class="selector-class">.square</span><span class="selector-pseudo">::after</span> &#123;</span><br><span class="line">    <span class="attribute">content</span>: <span class="string">&#x27;&#x27;</span>;</span><br><span class="line">    <span class="attribute">display</span>: block;</span><br><span class="line">    <span class="attribute">width</span>: <span class="number">0</span>;</span><br><span class="line"></span><br><span class="line">    <span class="comment">/* margin的百分比相对于父元素的宽 */</span></span><br><span class="line">    <span class="attribute">margin-top</span>: <span class="number">100%</span>;</span><br><span class="line"></span><br><span class="line">    <span class="comment">/* 使用 padding也是可以的，这就不用父容器 BFC了 */</span></span><br><span class="line">    <span class="comment">/* padding-top: 100%; */</span></span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>

<br>

<h4 id="等腰三角形"><a href="#等腰三角形" class="headerlink" title="等腰三角形"></a>等腰三角形</h4><p>​    将宽高设为0</p>
<p>​    设置四周的 border</p>
<img src="https://typora555.oss-cn-shanghai.aliyuncs.com/typora555/image-20210908223602264.png" alt="image-20210908223602264" style="width:100px" />



<p>​    将三边border设置为透明：</p>
<img src="https://typora555.oss-cn-shanghai.aliyuncs.com/typora555/image-20210908225950082.png" alt="image-20210908225950082" style="width:100px" />



<figure class="highlight css"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br></pre></td><td class="code"><pre><span class="line"><span class="selector-class">.triangle</span> &#123;</span><br><span class="line">    <span class="attribute">width</span>: <span class="number">0</span>;</span><br><span class="line">    <span class="attribute">height</span>: <span class="number">0</span>;</span><br><span class="line">    <span class="attribute">border</span>: <span class="number">5rem</span> solid <span class="built_in">rgba</span>(<span class="number">0</span>, <span class="number">0</span>, <span class="number">0</span>, <span class="number">0</span>);</span><br><span class="line">    <span class="attribute">border-bottom</span>: <span class="number">5rem</span> solid black;</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>

<br>

<h4 id="直角梯形"><a href="#直角梯形" class="headerlink" title="直角梯形"></a>直角梯形</h4><p>​    将宽高设为0</p>
<p>​    设置四周的 border</p>
<img src="https://typora555.oss-cn-shanghai.aliyuncs.com/typora555/image-20210908225045436.png" alt="image-20210908225045436" style="width:100px" />

<p>​    </p>
<p>​    border-top: 0;</p>
<img src="https://typora555.oss-cn-shanghai.aliyuncs.com/typora555/image-20210908225131527.png" alt="image-20210908225131527" style="width:100px" />

<p>​    将右边框变为透明之后将颜色统一</p>
<img src="https://typora555.oss-cn-shanghai.aliyuncs.com/typora555/image-20210908225204180.png" alt="image-20210908225204180" style="width:100px" />

<figure class="highlight css"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br></pre></td><td class="code"><pre><span class="line"><span class="selector-class">.leftTriangle</span> &#123;</span><br><span class="line">    <span class="attribute">width</span>: <span class="number">0</span>;</span><br><span class="line">    <span class="attribute">height</span>: <span class="number">0</span>;</span><br><span class="line">    <span class="attribute">border-top</span>: <span class="number">0</span>;</span><br><span class="line">    <span class="attribute">border-bottom</span>: <span class="number">50px</span> solid <span class="built_in">rgb</span>(<span class="number">0</span>, <span class="number">0</span>, <span class="number">0</span>);</span><br><span class="line">    <span class="attribute">border-left</span>: <span class="number">50px</span> solid <span class="built_in">rgb</span>(<span class="number">0</span>, <span class="number">0</span>, <span class="number">0</span>);</span><br><span class="line">    <span class="attribute">border-right</span>: <span class="number">50px</span> solid <span class="built_in">rgba</span>(<span class="number">0</span>, <span class="number">0</span>, <span class="number">0</span>, <span class="number">0</span>);</span><br><span class="line">    <span class="attribute">float</span>: left;</span><br><span class="line">    <span class="attribute">margin</span>: <span class="number">20px</span>;</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>



<h4 id="等腰梯形"><a href="#等腰梯形" class="headerlink" title="等腰梯形"></a>等腰梯形</h4><p>​    设置相等宽高</p>
<p>​    设置四周相等的 border</p>
<img src="https://typora555.oss-cn-shanghai.aliyuncs.com/typora555/image-20210908230844656.png" alt="image-20210908230844656" style="width:100px" />

<p>​    将其中三边颜色设为透明</p>
<img src="https://typora555.oss-cn-shanghai.aliyuncs.com/typora555/image-20210908231307441.png" alt="image-20210908231307441" style="width:110px" />

<figure class="highlight css"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br></pre></td><td class="code"><pre><span class="line"><span class="selector-class">.triangle</span> &#123;</span><br><span class="line">    <span class="attribute">width</span>: <span class="number">50px</span>;</span><br><span class="line">    <span class="attribute">height</span>: <span class="number">50px</span>;</span><br><span class="line">    <span class="attribute">border-top</span>: <span class="number">50px</span> solid <span class="built_in">rgba</span>(<span class="number">0</span>, <span class="number">0</span>, <span class="number">0</span>, <span class="number">0</span>);</span><br><span class="line">    <span class="attribute">border-bottom</span>: <span class="number">50px</span> solid <span class="built_in">rgb</span>(<span class="number">96</span>, <span class="number">255</span>, <span class="number">90</span>);</span><br><span class="line">    <span class="attribute">border-left</span>: <span class="number">50px</span> solid <span class="built_in">rgba</span>(<span class="number">0</span>, <span class="number">0</span>, <span class="number">0</span>, <span class="number">0</span>);</span><br><span class="line">    <span class="attribute">border-right</span>: <span class="number">50px</span> solid <span class="built_in">rgba</span>(<span class="number">0</span>, <span class="number">0</span>, <span class="number">0</span>, <span class="number">0</span>);</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>



<h4 id="圆与椭圆"><a href="#圆与椭圆" class="headerlink" title="圆与椭圆"></a>圆与椭圆</h4><img src="https://typora555.oss-cn-shanghai.aliyuncs.com/typora555/image-20210908232415598.png" alt="image-20210908232415598" style="width:120px" />



<figure class="highlight css"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br></pre></td><td class="code"><pre><span class="line"><span class="selector-class">.circle</span> &#123;</span><br><span class="line">    <span class="attribute">width</span>: <span class="number">10rem</span>;</span><br><span class="line">    <span class="attribute">height</span>: <span class="number">10rem</span>;</span><br><span class="line"></span><br><span class="line">    <span class="comment">/* 通过 border-radius:50%实现 */</span></span><br><span class="line">    <span class="attribute">border-radius</span>: <span class="number">50%</span>;</span><br><span class="line">    <span class="attribute">background-color</span>: black;</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>



<br>

<img src="https://typora555.oss-cn-shanghai.aliyuncs.com/typora555/image-20210909002520040.png" alt="image-20210909002520040" style="width:180px;" />



<p>​    在圆形的基础上调整长宽比就变成椭圆了 </p>
<figure class="highlight css"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br></pre></td><td class="code"><pre><span class="line"><span class="selector-class">.ellipse</span> &#123;</span><br><span class="line">    <span class="attribute">height</span>: <span class="number">5rem</span>;</span><br><span class="line">    <span class="attribute">height</span>: <span class="number">10rem</span>;</span><br><span class="line">    <span class="attribute">border-radius</span>: <span class="number">50%</span>;</span><br><span class="line">    <span class="attribute">background-color</span>: black;</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>



<h4 id="平行四边形"><a href="#平行四边形" class="headerlink" title="平行四边形"></a>平行四边形</h4><img src="https://typora555.oss-cn-shanghai.aliyuncs.com/typora555/image-20210908233102189.png" alt="image-20210908233102189" style="width:120px"  />



<figure class="highlight css"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br></pre></td><td class="code"><pre><span class="line"><span class="selector-class">.square</span> &#123;</span><br><span class="line">    <span class="attribute">width</span>: <span class="number">10rem</span>;</span><br><span class="line">    <span class="attribute">height</span>: <span class="number">10rem</span>;</span><br><span class="line">    <span class="attribute">background-color</span>: black;</span><br><span class="line"></span><br><span class="line">    <span class="comment">/* 将锚点移动到左上角 */</span></span><br><span class="line">    <span class="attribute">transform-origin</span>: <span class="number">0</span> <span class="number">100%</span>;</span><br><span class="line"></span><br><span class="line">    <span class="comment">/* 通过设置倾斜转换 skew实现角度，如果不熟悉建议去控制台调值观察变化 */</span></span><br><span class="line">    <span class="attribute">transform</span>: <span class="built_in">skewX</span>(-<span class="number">10deg</span>);</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>



<h4 id="任意角度扇形"><a href="#任意角度扇形" class="headerlink" title="任意角度扇形"></a>任意角度扇形</h4><img src="https://typora555.oss-cn-shanghai.aliyuncs.com/typora555/image-20210908233929505.png" alt="image-20210908233929505" style="width:150px" />



<p>通过效果图可以看出扇形是用四个小扇形拼接而成的，如何操作呢？</p>
<figure class="highlight html"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br><span class="line">39</span><br><span class="line">40</span><br><span class="line">41</span><br><span class="line">42</span><br><span class="line">43</span><br><span class="line">44</span><br><span class="line">45</span><br><span class="line">46</span><br><span class="line">47</span><br><span class="line">48</span><br><span class="line">49</span><br><span class="line">50</span><br><span class="line">51</span><br><span class="line">52</span><br><span class="line">53</span><br><span class="line">54</span><br><span class="line">55</span><br><span class="line">56</span><br><span class="line">57</span><br><span class="line">58</span><br><span class="line">59</span><br><span class="line">60</span><br><span class="line">61</span><br><span class="line">62</span><br><span class="line">63</span><br><span class="line">64</span><br><span class="line">65</span><br><span class="line">66</span><br><span class="line">67</span><br><span class="line">68</span><br><span class="line">69</span><br><span class="line">70</span><br><span class="line">71</span><br><span class="line">72</span><br><span class="line">73</span><br></pre></td><td class="code"><pre><span class="line"><span class="meta">&lt;!DOCTYPE <span class="meta-keyword">html</span>&gt;</span></span><br><span class="line"><span class="tag">&lt;<span class="name">html</span> <span class="attr">lang</span>=<span class="string">&quot;en&quot;</span>&gt;</span></span><br><span class="line"></span><br><span class="line"><span class="tag">&lt;<span class="name">head</span>&gt;</span></span><br><span class="line">  <span class="tag">&lt;<span class="name">meta</span> <span class="attr">charset</span>=<span class="string">&quot;UTF-8&quot;</span>&gt;</span></span><br><span class="line">  <span class="tag">&lt;<span class="name">meta</span> <span class="attr">http-equiv</span>=<span class="string">&quot;X-UA-Compatible&quot;</span> <span class="attr">content</span>=<span class="string">&quot;IE=edge&quot;</span>&gt;</span></span><br><span class="line">  <span class="tag">&lt;<span class="name">meta</span> <span class="attr">name</span>=<span class="string">&quot;viewport&quot;</span> <span class="attr">content</span>=<span class="string">&quot;width=device-width, initial-scale=1.0&quot;</span>&gt;</span></span><br><span class="line">  <span class="tag">&lt;<span class="name">title</span>&gt;</span>Document<span class="tag">&lt;/<span class="name">title</span>&gt;</span></span><br><span class="line">  <span class="tag">&lt;<span class="name">style</span>&gt;</span><span class="css"></span></span><br><span class="line"><span class="css">    * &#123;</span></span><br><span class="line"><span class="css">      <span class="attribute">list-style</span>: none;</span></span><br><span class="line"><span class="css">      <span class="attribute">padding</span>: <span class="number">0</span>;</span></span><br><span class="line"><span class="css">      <span class="attribute">margin</span>: <span class="number">0</span>;</span></span><br><span class="line"><span class="css">    &#125;</span></span><br><span class="line"><span class="css"></span></span><br><span class="line"><span class="css">    <span class="selector-class">.pie</span> &#123;</span></span><br><span class="line"><span class="css">      <span class="attribute">width</span>: <span class="number">10rem</span>;</span></span><br><span class="line"><span class="css">      <span class="attribute">height</span>: <span class="number">10rem</span>;</span></span><br><span class="line"><span class="css">      <span class="attribute">border-radius</span>: <span class="number">50%</span>;</span></span><br><span class="line"><span class="css"></span></span><br><span class="line"><span class="css">      </span></span><br><span class="line"><span class="css">      <span class="comment">/* 对倾斜转换超出的部分隐藏，学习阶段建议注释观察变化 */</span></span></span><br><span class="line"><span class="css">      <span class="attribute">overflow</span>: hidden;</span></span><br><span class="line"><span class="css">      <span class="attribute">position</span>: relative;</span></span><br><span class="line"><span class="css">    &#125;</span></span><br><span class="line"><span class="css"></span></span><br><span class="line"><span class="css">    <span class="selector-class">.slice</span> &#123;</span></span><br><span class="line"><span class="css">      <span class="attribute">width</span>: <span class="number">50%</span>;</span></span><br><span class="line"><span class="css">      <span class="attribute">height</span>: <span class="number">50%</span>;</span></span><br><span class="line"><span class="css"></span></span><br><span class="line"><span class="css">      <span class="comment">/* 设置锚点在矩形右下角 */</span></span></span><br><span class="line"><span class="css">      <span class="attribute">transform-origin</span>: <span class="number">100%</span> <span class="number">100%</span>;</span></span><br><span class="line"><span class="css"></span></span><br><span class="line"><span class="css">      <span class="comment">/* 需要开启绝对定位使其重叠在一起 */</span></span></span><br><span class="line"><span class="css">      <span class="attribute">position</span>: absolute;</span></span><br><span class="line"><span class="css">    &#125;</span></span><br><span class="line"><span class="css"></span></span><br><span class="line"><span class="css">    <span class="comment">/* 分别设置四个 1/4 圆的 角度、倾斜度以及颜色透明度来拼接目标度数的扇形 */</span></span></span><br><span class="line"><span class="css">    <span class="selector-class">.slice-1</span> &#123;</span></span><br><span class="line"><span class="css">      <span class="attribute">background-color</span>: <span class="built_in">rgb</span>(<span class="number">255</span>, <span class="number">85</span>, <span class="number">85</span>);</span></span><br><span class="line"><span class="css"></span></span><br><span class="line"><span class="css">      <span class="comment">/* 通过设置倾斜转换 skew实现角度，推荐去控制台调整观察变化 */</span></span></span><br><span class="line"><span class="css">      <span class="attribute">transform</span>: <span class="built_in">skewX</span>(<span class="number">0deg</span>) <span class="built_in">rotate</span>(<span class="number">0deg</span>);</span></span><br><span class="line"><span class="css">    &#125;</span></span><br><span class="line"><span class="css"></span></span><br><span class="line"><span class="css">    <span class="selector-class">.slice-2</span> &#123;</span></span><br><span class="line"><span class="css">      <span class="attribute">background-color</span>: <span class="built_in">rgb</span>(<span class="number">255</span>, <span class="number">238</span>, <span class="number">85</span>);</span></span><br><span class="line"><span class="css">      <span class="attribute">transform</span>: <span class="built_in">skewX</span>(<span class="number">00deg</span>) <span class="built_in">rotate</span>(-<span class="number">90deg</span>);</span></span><br><span class="line"><span class="css">    &#125;</span></span><br><span class="line"><span class="css"></span></span><br><span class="line"><span class="css">    <span class="selector-class">.slice-3</span> &#123;</span></span><br><span class="line"><span class="css">      <span class="attribute">background-color</span>: <span class="built_in">rgb</span>(<span class="number">85</span>, <span class="number">215</span>, <span class="number">255</span>);</span></span><br><span class="line"><span class="css">      <span class="attribute">transform</span>: <span class="built_in">skewX</span>(<span class="number">0deg</span>) <span class="built_in">rotate</span>(-<span class="number">180deg</span>);</span></span><br><span class="line"><span class="css">    &#125;</span></span><br><span class="line"><span class="css"></span></span><br><span class="line"><span class="css">    <span class="selector-class">.slice-4</span> &#123;</span></span><br><span class="line"><span class="css">      <span class="attribute">background-color</span>: <span class="built_in">rgb</span>(<span class="number">119</span>, <span class="number">255</span>, <span class="number">85</span>);</span></span><br><span class="line"><span class="css">      <span class="attribute">transform</span>: <span class="built_in">skewX</span>(-<span class="number">30deg</span>) <span class="built_in">rotate</span>(-<span class="number">270deg</span>);</span></span><br><span class="line"><span class="css">    &#125;</span></span><br><span class="line"><span class="css">  </span><span class="tag">&lt;/<span class="name">style</span>&gt;</span></span><br><span class="line"><span class="tag">&lt;/<span class="name">head</span>&gt;</span></span><br><span class="line"></span><br><span class="line"><span class="tag">&lt;<span class="name">body</span>&gt;</span></span><br><span class="line">  <span class="tag">&lt;<span class="name">ul</span> <span class="attr">class</span>=<span class="string">&#x27;pie&#x27;</span>&gt;</span></span><br><span class="line">    <span class="comment">&lt;!-- 一个 slice最高仅能实现 90°扇形 超出最多四个 slice进行拼接 --&gt;</span></span><br><span class="line">    <span class="tag">&lt;<span class="name">li</span> <span class="attr">class</span>=<span class="string">&#x27;slice-1 slice&#x27;</span>&gt;</span> <span class="tag">&lt;/<span class="name">li</span>&gt;</span></span><br><span class="line">    <span class="tag">&lt;<span class="name">li</span> <span class="attr">class</span>=<span class="string">&#x27;slice-2 slice&#x27;</span>&gt;</span> <span class="tag">&lt;/<span class="name">li</span>&gt;</span></span><br><span class="line">    <span class="tag">&lt;<span class="name">li</span> <span class="attr">class</span>=<span class="string">&#x27;slice-3 slice&#x27;</span>&gt;</span> <span class="tag">&lt;/<span class="name">li</span>&gt;</span></span><br><span class="line">    <span class="tag">&lt;<span class="name">li</span> <span class="attr">class</span>=<span class="string">&#x27;slice-4 slice&#x27;</span>&gt;</span> <span class="tag">&lt;/<span class="name">li</span>&gt;</span></span><br><span class="line">    <span class="tag">&lt;<span class="name">ul</span>&gt;</span></span><br><span class="line"><span class="tag">&lt;/<span class="name">body</span>&gt;</span></span><br><span class="line"></span><br><span class="line"><span class="tag">&lt;/<span class="name">html</span>&gt;</span></span><br></pre></td></tr></table></figure>





<p>&nbsp;&nbsp;&nbsp;&nbsp;通过以上的基本图案还可以进行拼接，形成菱形、五边形、砖石、六边形、六角形、等等图案，快试试看吧！</p>

    </div>

    
    
    

    <footer class="post-footer">
          <div class="post-tags">
              <a href="/tags/HTML/" rel="tag"># HTML</a>
              <a href="/tags/CSS/" rel="tag"># CSS</a>
          </div>

        

          <div class="post-nav">
            <div class="post-nav-item">
                <a href="/width%E5%8C%BA%E5%88%AB/" rel="prev" title="width:100&#37与auto的区别">
                  <i class="fa fa-chevron-left"></i> width:100&#37与auto的区别
                </a>
            </div>
            <div class="post-nav-item">
                <a href="/%E5%AE%A2%E6%88%B7%E7%AB%AF%E4%BD%BF%E7%94%A8WebSockets/" rel="next" title="客户端使用 WebSockets">
                  客户端使用 WebSockets <i class="fa fa-chevron-right"></i>
                </a>
            </div>
          </div>
    </footer>
  </article>
</div>






</div>
  </main>

  <footer class="footer">
    <div class="footer-inner">


<div class="copyright">
  &copy; 
  <span itemprop="copyrightYear">2021</span>
  <span class="with-love">
    <i class="fa fa-heart"></i>
  </span>
  <span class="author" itemprop="copyrightHolder">受靈夢</span>
</div>

    </div>
  </footer>

  
  <script src="https://cdn.jsdelivr.net/npm/animejs@3.2.1/lib/anime.min.js" integrity="sha256-XL2inqUJaslATFnHdJOi9GfQ60on8Wx1C2H8DYiN1xY=" crossorigin="anonymous"></script>
<script src="/js/comments.js"></script><script src="/js/utils.js"></script><script src="/js/motion.js"></script><script src="/js/next-boot.js"></script>

  
<script src="/js/third-party/search/local-search.js"></script>




  





</body>
</html>
